package org.dromara.germbank.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.constant.SystemConstants;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.germbank.domain.BusPartnerClinic;
import org.dromara.germbank.domain.BusPartnerPartner;

import org.dromara.germbank.domain.bo.BusPartnerPartnerBo;
import org.dromara.germbank.domain.vo.BusPartnerPartnerVo;
import org.dromara.germbank.mapper.BusPartnerPartnerMapper;
import org.dromara.germbank.service.BusPartnerPartnerService;
import org.springframework.stereotype.Service;

/**
 * 商业伙伴实现类
 *
 * @author congxing
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class BusPartnerPartnerServiceImpl implements BusPartnerPartnerService {

    private final BusPartnerPartnerMapper busPartnerPartnerMapper;


    @Override
    public TableDataInfo<BusPartnerPartnerVo> queryPageList(BusPartnerPartnerBo bo, PageQuery pageQuery) {
        Page<BusPartnerPartnerVo> page = busPartnerPartnerMapper.queryPageList(pageQuery.build(),this.buildQueryWrapper(bo));
        return TableDataInfo.build(page);
    }

    // 分页查询条件
    private Wrapper<BusPartnerPartner> buildQueryWrapper(BusPartnerPartnerBo bo) {
        return Wrappers.<BusPartnerPartner>lambdaQuery()
            // 逻辑删除字段（固定条件）
            .eq(BusPartnerPartner::getDelFlag, SystemConstants.NORMAL)

            // 诊所名称（模糊）
            .like(StringUtils.isNotBlank(bo.getClinicName()),
                BusPartnerPartner::getClinicName, bo.getClinicName())



            // 排序
            .orderByAsc(BusPartnerPartner::getId);
    }
}
